//
//  ViewController.m
//  16-runloop 自动释放池
//
//  Created by J on 16/2/26.
//  Copyright © 2016年 J. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    NSLog(@"%@",[NSRunLoop currentRunLoop]);

    NSThread *thread = [[NSThread alloc]initWithTarget:self selector:@selector(star) object:nil];
    [thread start];

}

- (void)star{
    
    //    NSLog(@"%d",0xa0);
    
    //    CF的内存管理（Core Foundation）
    //    凡是带有Create、Copy、Retain等字眼的函数，创建出来的对象，都需要在最后做一次release
    //    比如CFRunLoopObserverCreate
    //    release函数：CFRelease(对象);
    
    CFRunLoopObserverRef observer  =  CFRunLoopObserverCreateWithHandler(CFAllocatorGetDefault(), kCFRunLoopAllActivities, YES, 0, ^(CFRunLoopObserverRef observer, CFRunLoopActivity activity) {
        
        NSLog(@"%zd",activity);
        
        
    });
    CFRunLoopAddObserver(CFRunLoopGetCurrent(), observer, kCFRunLoopDefaultMode);//添加timer或者source
    CFRelease(observer);

//    [[NSRunLoop currentRunLoop]addPort:[NSPort port] forMode:NSDefaultRunLoopMode];
    [[NSRunLoop currentRunLoop]run];
        NSLog(@"%@",[NSRunLoop currentRunLoop]);

    NSLog(@"---------");
}

@end
